package com.it.xml.plic.xml;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author げっしょく
 * @date 2021/8/11
 */
public class Demo1 {
    public static void main(String[] args) throws DocumentException {
        ArrayList<Students> list = new ArrayList<>();
        SAXReader sr = new SAXReader();
        Document read = sr.read(new File("D:\\IdeaProjects\\BasicCode\\Myxml\\XML\\student.xml"));
        Element rootElement = read.getRootElement();
        List<Element> s = rootElement.elements("student");
        for (Element element : s) {
            Attribute id = element.attribute("id");
            String value = id.getValue();
            Element name = element.element("name");
            Element age = element.element("age");
            String text = name.getText();
            String text1 = age.getText();
            System.out.println(value + "..." + text + "..." + text1);
            list.add(new Students(value, text , Integer.parseInt(text1)));
        }
        for (Students students : list) {
            System.out.println(students);
        }
    }
}
